package com.xunge.mapper;

import com.xunge.pojo.Homework;
import com.xunge.pojo.HomeworkQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HomeworkMapper {

    /**
     * 分页查询作业信息
     */
    List<Homework> list(HomeworkQueryParam homeworkQueryParam);

    /**
     * 新增作业
     */
    @Insert("insert into homework(title, content, course_id, clazz_id, teacher_id, due_date, status, create_time, update_time) " +
            "values(#{title}, #{content}, #{courseId}, #{clazzId}, #{teacherId}, #{dueDate}, #{status}, now(), now())")
    void insert(Homework homework);

    /**
     * 根据ID查询作业
     */
    @Select("select * from homework where id = #{id}")
    Homework getById(Integer id);

    /**
     * 根据ID修改作业
     *
     * @return
     */
    int update(Homework homework);

    /**
     * 根据ID删除作业
     */
    @Delete("delete from homework where id = #{id}")
    void deleteById(Integer id);

    /**
     * 批量删除作业
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 根据课程ID查询作业
     */
    @Select("select * from homework where course_id = #{courseId}")
    List<Homework> getByCourseId(Integer courseId);

    /**
     * 根据班级ID查询作业
     */
    @Select("select * from homework where clazz_id = #{clazzId}")
    List<Homework> getByClazzId(Integer clazzId);

    /**
     * 根据教师ID查询作业
     */
    @Select("select * from homework where teacher_id = #{teacherId}")
    List<Homework> getByTeacherId(Integer teacherId);

    /**
     * 查询所有已过期的作业（进行中状态且截止时间已过）
     * @return 过期作业列表
     */
    List<Homework> findExpiredHomeworks();
} 